<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test_User extends UnitTestController {
	public function __construct() {
		parent::__construct();
		$this->load->Model('UserDB');
		$this->load->library('webserviceresponse');
	}

	public function valid_for_insert() {
		$this->load->library('../controllers/user');

		// test case 1
		$result = $this->user->_validInputForInsert();
		$this->unit->run($result, 'is_true', 'Function user->_validInputForInsert', "all params POST null");

		// print reporting
		echo $this->unit->report();
	}

	public function insert() {
// 		$this->load->library('../controllers/user');

// 		// case
// 		$result = $this->user->insert();
// 		$this->unit->run($result, 'is_object', 'Function controllers user/insert', "all params POST null");


		// test case 1
		$result = $this->UserDB->insert(array('email' => 'a1@a.a'
				, 'password' => '123'));
		$this->unit->run($result, true, 'Function UserDB->insert', "insert user email, password");

// 		$result = $this->UserDB->insert(array('email' => 'a2@a.a'
// 				, 'password' => '123'
// 				, 'created'  => date('Y-m-d H:i:s')));

// 		// test case 2
// 		$this->unit->run($result, true, 'Function UserDB->insert', "insert user email, password, created");

// 		// test case 2
// 		$this->unit->run($result, '-1', 'Function validInput', $note);

// 		//test
// 		$this->run('dat', 'dat');

		// print reporting
		echo $this->unit->report();

	}

	function do_upload()
	{


		$this->load->library('myupload');

		$this->myupload->deleteFile('1363539686.jpg'); //
		die;

		$result = $this->myupload->doUpload();
		if(! is_array($result)) {
			$error = array('error' => $result);
			$this->load->view('upload_form', $error);
		} else {

			// resize
			$res = $this->myupload->resizeImage($result['full_path'], 1, 600, 800);
			var_dump($res);
			$res = $this->myupload->resizeImage($result['full_path'], 2, 188, 188);
			var_dump($res);



			$data = array('upload_data' =>$result);
			echo '<pre>';
			print_r($data);
			echo '</pre>';
		}


// 		$config['upload_path'] = "public/uploads/";
// 		$config['allowed_types'] = 'gif|jpg|png';
// 		$config['max_size']	= '100';
// 		$config['encrypt_name'] = true;
// 		$config['overwrite'] = true;
// 		$config['file_name'] = time();

// 		$this->load->library('upload', $config);

// 		if ( ! $this->upload->do_upload())
// 		{
// 			$error = array('error' => $this->upload->display_errors());

// // 			echo '<pre>';
// // 			print_r($error);
// // 			echo '</pre>';
// 			$this->load->view('upload_form', $error);
// 		}
// 		else
// 		{
// 			$data = array('upload_data' => $this->upload->data());

// 			echo '<pre>';
// 			print_r($data);
// 			echo '</pre>';
// 		}
	}


}